<template>
  <div class="template-index-Lu">
    <commpVxeTable
      :key="reCommpVxeTable"
      :conditionBtnRow="true"
      :config="dataTableConfig"
      :columns="columnsVxe"
      :formItem="formItem"
      @checkboxChange="checkboxChange"
      ref="administrativeOffice"
      @searchEvent="searchEvent"
      @resetEvent="resetEvent"
      >
      <template v-slot:externalOperations="{data}"  >
        <vxe-form-item>
            <template>
                <a-button class="blue-btn" style="margin-right:10px;" @click="addFor()">申请</a-button>
            </template>
        </vxe-form-item>
        <vxe-form-item>
            <template>
                <a-button class="red-btn" @click="deleteList()">批量删除</a-button>
            </template>
        </vxe-form-item>
      </template>
      <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
        <a-form layout="inline">
          <a-form-item>
              <a-button class="blue-btn" @click="viewRor(row)">查看</a-button>
          </a-form-item>
            <a-form-item>
                <a-popconfirm
                    title="您确定要删除这条申请吗?"
                    ok-text="确定"
                    cancel-text="取消"
                    @confirm="deleteFor(row)"
                    @cancel="cancel"
                    >
                        <a-button class="red-btn">删除</a-button>
                </a-popconfirm>
          </a-form-item>
        </a-form>
      </template>
    </commpVxeTable>
    <applicationForm ref="applicationFormRef" :formData="formData" :linkName="linkName" :stepNums="stepNums"  @success="success"></applicationForm>
  </div>
</template>
<script>
import assessCheckApi from './service/api.js'
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
import applicationForm from './applicationForm'
import {deleteJbzbFlowJob} from './service/index.js'
export default {
  components: {
    commpVxeTable,
    applicationForm,
  },
  props:{
    linkName:{
      type:String,
      default:'',
      required:false,
    },
    stepNum:{
      type:String,
      default:'',
      required:false,
    }
  },
  data() {
    return {
      reCommpVxeTable: '',
      dataTableConfig: {
        api: assessCheckApi.list,
        rowId: 'id',
        urlType: true,
        paramet:{
          fhjmc: this.linkName,
        }
      },
      columnsVxe: [
        {
          type: 'checkbox',
          width: 60,
          fixed: 'left'
        },{
          title: '发送人',
          field: 'ffsrmc',
          width: 100,
        },{
          title: '发送时间',
          field: 'ffssj',
          width: 150,
        },{
          title: '加班/值班事由',
          field: 'fjbzbsy',
        },{
          title: '加班/值班开始时间',
          field: 'fjbzbkssj',
          width: 150,
        },{
          title: '加班/值班结束时间',
          field: 'fjbzbjssj',
          width: 150,
        },{
          title: '时长',
          field: 'fjbzbsc',
          width: 150,
        },{
          title: '退回意见',
          field: 'fthyj',
          width: 100,
        },{
          title: '操作',
          field: 'jobid',
          width: 200,
          slots: {
          // 使用插槽模板渲染
            default: 'operation_btn',
          },
        }
      ],
      formItem: [
        {
          label: '事由',
          model: 'fjbzbsy',
        },{
          label: '类别',
          model: 'flb',
          placeholder: '类别',
          type:'Select',
          dictionaryType:''
        }
      ],
      jobidList: [],
      stepNums: 0,
      formData: {},

    }
  },
  created(){
    this.stepNums = Number(this.stepNum)
  },
  methods: {
     // 勾选
     checkboxChange(val){
      //console.log('已选择',val)
      this.jobidList = []
      if(val.length){
        val.forEach(item => {
            this.jobidList.push(item.jobid)
        });
      }
    },
    // 搜索
    searchEvent(){
      this.dataTableConfig.paramet = {
          ...this.dataTableConfig.paramet,
      }
      //console.log(this.dataTableConfig.paramet)
    },
    // 重置
    resetEvent(){
      this.dataTableConfig.paramet = {
          ...this.dataTableConfig.paramet,
      }
    },
    // 添加申请
    addFor(){
        this.$nextTick(_ => {
            this.$refs.applicationFormRef.applicationFormVisible= true
        })
    },
    // 删除
    deleteFor(row){
      deleteJbzbFlowJob({jobids:row.jobid}).then(res => {
            //console.log(res)
            if(res.code == 200){
                this.reCommpVxeTable = Date.now()
                this.$message.success(res.message)
            } else {
                this.$message.warning(res.message)
            }
        })
    },
    cancel(e) {
        //console.log(e);
    },
    // 批量删除
    deleteList(){
      var that = this
      if(that.jobidList.length == 0){
        that.$message.warning('请选择删除项目')
      } else {
        that.$confirm({
          title: '您确定要删除这些申请吗?',
          content: '',
          okText: '确定',
          okType: 'danger',
          cancelText: '取消',
          onOk() {
            let list = that.jobidList.toString()
            deleteJbzbFlowJob({jobids:list}).then(res => {
              //console.log(res)
              if(res.code == 200){
                that.reCommpVxeTable = Date.now()
                that.$message.success(res.message)
              } else {
                that.$message.warning(res.message)
              }
            })
          },
          onCancel() {
            //console.log('Cancel');
          },
        });
      }
    },
    // 办理
    viewRor(row){
      this.formData = {
        ...row
      }
      this.formData.id = row.oaid

      let jobid = row.jobid
      // queryJobByJobId({jobid:jobid}).then(res => {
      //   //console.log(res)
      // })
        this.$nextTick(_ => {
            this.$refs.applicationFormRef.applicationFormVisible= true
        })
    },
    // 弹窗提交成功
    success(){
      // 刷新表格 清空id数组
      this.$refs.administrativeOffice.resetEvent()
      this.jobidList = []
    },
  },
}
</script>
<style>
@import url('../../css/oaClass.css');
</style>
